<div class="container-fluid suredy-form" style="padding-top: 0">
	<div class="row">	
	<form name="form" id="form">
	  <#if resource??>
	  	<input type="hidden" id="id" value="${resource.id}" />
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">资源名称</div>
				<input type="text" class="form-control" id="name" value="${resource.name}" />
			</div>
		</div>
	
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">资源标识</div>
				<input type="text" class="form-control" id="uri" value="${resource.uri}" />
			</div>
		</div>	
	
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">控制类型</div>
				<select class="form-control" id="type">
					<option value="">请选择...</option>
					<#if types??><#list types as type>
						<#assign isSelected = "" />
						<#if (resource.type == type.getType()) >
			                <#assign isSelected = "selected=\"selected\"" />	            	  
			            </#if>
					  <option ${isSelected} value="${type.getType()}">${type.getDescription()}</option>
					</#list> </#if>	
				</select>
			</div>
		</div>	
	  </#if>												
		<div class="text-center">
			<button class="btn btn-info" id="btn-save" type="button">
				<i class="icon-save"></i>
				保存
			</button>
		</div>	
	</form>	
	</div>
</div>

<script type="text/javascript">
	$(document).ready(function() {
		
		$('#btn-save').click(function() {
			var id = $('#id').val();
			var name = $('#name').val();
			var uri = $('#uri').val();
			var type = $('#type').val();
			if (name == '') {
				alert('请填写名称！');
				return;
			}

			if (uri == '') {
				alert('请填写标识！');
				return;
			}
			
			if (type == '') {
				alert('请选择控制类型！');
				return;
			}

			$.ajax({
				url : 'resource-save.do',
				dataType : 'json',
				type : 'POST',
				data : {
					id : id,
					name : name,
					uri : uri,
					type : type
				},
				success : function(success) {
					if (!success) {
						alert('修改安全资源失败！');
					} else if (!success.success) {
						alert('修改安全资源成功！\n\n' + success.msg);
					} else {
						alert('修改安全资源成功！');
						$.suredy.loadContent('resource-list.do');
						$.suredy.closeModal();
					}
				},
				error : function(a, b, c) {
					alert('服务器错误! ' + b);
				}
			});
		});	
	});
</script>	
